package com.nucarf.yc.app

import com.alibaba.fastjson.{JSON, JSONObject}
import com.nucarf.yc.bean.{Order, OrderInfo, OrderSum}
import org.apache.flink.table.expressions.DateFormat

import java.text.SimpleDateFormat
import scala.collection.mutable
import scala.collection.mutable.HashMap

object TestJson {

  def main(args: Array[String]): Unit = {
    val json: String = "{\"database\":\"yidian_ceshi\",\"table\":\"tb_nc_member_order_info\",\"type\":\"insert\",\"ts\":1631070469,\"xid\":178047739,\"commit\":true,\"position\":\"mysql-bin.000339:14796697\",\"data\":{\"moi_id\":5853323,\"member_id\":215267}}"

    val value: Order = jsonToBean[Order](new Order, json)
    var orderMap: HashMap[String, String] = new HashMap[String, String]
    orderMap+=(("1", "wdl"))

    val decimal: BigDecimal = BigDecimal.apply("1123.22222")
    var s: Long = 1632649483
    val newtime :String = new SimpleDateFormat("yyyy-MM").format(s * 1000)

    val hashSet = new mutable.HashSet[String]

    hashSet.add("1")
    hashSet.add("wdl")
    hashSet.add("wdl")

    print(hashSet.size)
    print(hashSet)
  }


  /**
   * json 字符串转换成实体类
   * @param t 实体类类型
   * @param dataJson 要转成实体类的 json 字符串
   * @tparam T 返回实体类对象
   * @return
   */
  def jsonToBean[T](t: T, dataJson: String): T = {

    val jsonObject: JSONObject = JSON.parseObject(dataJson)
    val value: String = jsonObject.get("data").toString
    val t1: T = JSON.parseObject(value, t.getClass)
    t1
  }

}
